# Create your views here.
from django.template import Context, loader
from django.http import HttpResponse
from django.conf.urls.defaults import *
from api.models import Author, Book, Price


urlpatterns = patterns('product.views',
    (r'^(?P<product_id>\d+)/$',    'detail'),
    )

def detail(request, product_id):
    books = Book.objects.filter(uuid=product_id)
    authors = None
    prices = None
    
    if books.count() < 1:
        b = None
    else:
        b = books[0]
        
        authors = b.author_set.all()
        prices = b.price_set.all()
        
        
    t = loader.get_template('templates/product_template.html')
    c = Context({
        'book': b,
        'authors': authors,
        'prices': prices,
    })
        
    return HttpResponse(t.render(c))
